<script setup lang='ts'>

import { onMounted, ref } from 'vue';

const inpRef = ref<HTMLInputElement | null>(null)

onMounted(() => {
  // 1.非空断言
  // inpRef.value!.focus()
  // 2.可选
  inpRef.value?.focus()
  // 3.判断
  if (inpRef.value) {
    inpRef.value!.focus()
  }
})
const aRef = ref<HTMLAnchorElement | null>(null)
onMounted(() => {
  aRef.value!.href = 'sdfsklfj'
})

</script>


<template>
  <div>
    <input type="text" ref="inpRef">
    <a href="#" ref="aRef">点我呀</a>
  </div>
</template>

<style scoped></style>